from db import db
from db import BaseFul
from werkzeug.security import check_password_hash, generate_password_hash


class App_user(BaseFul):
    name = db.Column(db.String(20), default='tony')
    image = db.Column(db.TEXT, nullable=True)
    is_login = db.Column(db.Boolean(), default=False)
    phone = db.Column(db.String(11))
    _pwd = db.Column(db.VARCHAR(256))
    email = db.Column(db.VARCHAR(50))
    sex = db.Column(db.SMALLINT)
    create = db.Column(db.Date)
    area = db.Column(db.VARCHAR(50))
    is_vip = db.Column(db.Boolean(), default=False)
    age = db.Column(db.SMALLINT)

    @property
    def password(self):
        raise Exception('不准查看')

    @password.setter
    def password(self, password_value):
        self._pwd = generate_password_hash(password_value)

    def check_password(self, user_password):
        return check_password_hash(self._pwd, user_password)

    def check_permission(self, permission_s):
        return self.is_vip
